/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dw2;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author Alberto
 */
public class PauseMenu extends Menu implements ActionListener {
    private ImageButton resume;
    private ImageButton restart;
    private ImageButton help;
    private ImageButton highscores;
    private ImageButton quit;

    public PauseMenu(Main parent, Image[] images) {
        super(parent, null);
        resume = new ImageButton(images[0], "Resume", 312, 50);
        restart = new ImageButton(images[1], "Restart", 312, 50);
        help = new ImageButton(images[2], "Help", 272, 40);
        highscores = new ImageButton(images[3], "Highscores", 278, 43);
        quit = new ImageButton(images[4], "Quit", 260, 44);
        resume.setAlignmentX(Component.CENTER_ALIGNMENT);
        restart.setAlignmentX(Component.CENTER_ALIGNMENT);
        help.setAlignmentX(Component.CENTER_ALIGNMENT);
        highscores.setAlignmentX(Component.CENTER_ALIGNMENT);
        quit.setAlignmentX(Component.CENTER_ALIGNMENT);
        add(resume);
        add(restart);
        add(help);
        add(highscores);
        add(quit);
    }

    //call this before using menu; makes buttons responsive
    public void init() {
        resume.addActionListener(this);
        restart.addActionListener(this);
        help.addActionListener(this);
        highscores.addActionListener(this);
        quit.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        
        
        if(e.getActionCommand().equals("Resume")) {
            try {
                parent.MC.stopMenuMusic();
            }
            catch(Exception ex) {

            }
            parent.MC.play();
            parent.remove(this);
            parent.validate();
            parent.togglePaused();
            parent.requestFocusInWindow();
        }
        if(e.getActionCommand().equals("Restart")) {
        
         
            parent.reset_game();
            parent.togglePaused();
            parent.remove(this);
            parent.validate();
            parent.startGame();
        }
        if(e.getActionCommand().equals("Quit")) {
        
        
            parent.reset_game();
            parent.togglePaused();
            parent.remove(this);
            parent.add(parent.mainMenu);
            parent.MC.playMenuMusic(0);
            parent.validate();
            parent.repaint();
        }

        if(e.getActionCommand().equals("Help")) {

            parent.remove(this);
            parent.helpMenu.setFromStart(false);
            parent.add(parent.helpMenu);
            parent.MC.playMenuMusic(3);
            parent.validate();
            parent.repaint();
        }

        if(e.getActionCommand().equals("Highscores")) {
            parent.remove(this);
            parent.hscoreMenu.setFromStart(false);
            parent.add(parent.hscoreMenu);
            parent.MC.playMenuMusic(2);
            parent.validate();
            parent.repaint();
        }
    }

    public void captureBG() {
        image = parent.screenCapture();

        parent.track.addImage(image, 15);
        try
        {
            parent.track.waitForID(15);
        }
        catch(InterruptedException ex)
        {
        }
    }
}
